﻿using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Volo.Abp.Domain.Entities.Auditing;
using Xms.Abp.BackgroundJob;
using Xms.Abp.Data;
using Xms.Abp.Domain;

namespace BackgroundJobManagement;

[Table("BackgroundJob")]
[Index(nameof(Name))]
[Index(nameof(DisplayName))]
[Index(nameof(ScheduleId))]
[Index(nameof(NextTryTime))]
[Index(nameof(TryTimeoutTime))]
public class BackgroundJobEntity : FullAuditedAggregateRoot<Guid>, IHasName<Guid>, IHasDisplayName<Guid>, IHasRemark
{
    [Required]
    [MaxLength(128)]
    public virtual string Name { get; set; }

    [Required]
    [MaxLength(128)]
    public virtual string DisplayName { get; set; }

    public virtual string JobArgs { get; set; }

    public virtual Guid? ScheduleId { get; set; }

    [Required]
    [MaxLength(128)]
    public virtual string RetryIntervals { get; set; }

    public virtual short TryCount { get; set; }

    public virtual short? MaxTryCount { get; set; }

    public virtual DateTime NextTryTime { get; set; }

    public virtual DateTime? LastTryTime { get; set; }

    public virtual DateTime? TryTimeoutTime { get; set; }

    public virtual BackgroundJobStatus BackgroundJobStatus { get; set; }

    public virtual string ErrorMessage { get; set; }

    public virtual int? Timeout { get; set; }

    public virtual bool IsAbandoned { get; set; }

    public virtual BackgroundJobPriority Priority { get; set; }

    public string ReferenceJobs { get; set; }

    public Guid? TenantId { get; set; }

    public string Remark { get; set; }

    protected BackgroundJobEntity()
    {

    }

    public BackgroundJobEntity(Guid id)
        : base(id)
    {

    }
}
